package com.yuanqi.controller;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanqi.common.Result;
import com.yuanqi.pojo.CommodityBrand;
import com.yuanqi.service.CommodityBrandService;
import lombok.RequiredArgsConstructor;

import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 品牌管理接口
 */
@RestController
@RequestMapping("/api/brand")
@RequiredArgsConstructor
public class CommodityBrandController {

    private final CommodityBrandService brandService; // 注入服务

    /**
     * 获取全部品牌（用于下拉菜单）
     */
    @GetMapping("/list")
    public Result<List<CommodityBrand>> list() {
        return Result.success(brandService.list());
    }

    @PostMapping
    public Result<Boolean> create(@RequestBody CommodityBrand brand) {
        return Result.success(brandService.save(brand)); // 新增
    }

    @PutMapping
    public Result<Boolean> update(@RequestBody CommodityBrand brand) {
        return Result.success(brandService.updateById(brand)); // 修改
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.success(brandService.removeById(id)); // 删除
    }


}


